//
//  SEGMenuRequestManager.m
//  SEGPlatform
//
//  Created by 乔杨 on 2020/12/3.
//

#import "SEGMenuRequestManager.h"
#import "SEGPlatformManager.h"

#import "RACTuple.h"

#import "SEGMenuListManager.h"
#import "SEGMenulist2Manager.h"
#import "SEGParkMenuListManager.h"

@interface SEGMenuRequestManager ()

@property (nonatomic, strong) SEGParkMenuListManager *parkMenuListManager;
/// saas平台菜单请求类
@property (nonatomic, strong) SEGMenuListManager *menuListManager;

@end

@implementation SEGMenuRequestManager
 
#pragma mark - tabBar菜单
/// 请求菜单底部tabBar
/// @param completion 回调
+ (void)menu_requestMenuForTabBarCompletion:(void(^)(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage))completion {
    [[SEGMenulist2Manager sharedManager] segRequestMenuListForTabBarCompleted:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (completion) completion(isSuccessed, result, codeType, errorMessage);
    }];
}

#pragma mark - 页面菜单
/// 请求本地缓存菜单页面数据
/// @param action 页面编码
/// @param settingsId  导航菜单id
/// @param type 广告类型
/// @param completion 回调
- (void)menu_requestLocalMenuForPageWithAction:(NSString *)action settingsId:(NSString *)settingsId positionType:(SEGAdvlistType)type completion:(seg_menu_block)completion {
    [self.menuListManager segAsyncGetLocalDataWithAction:action PositionType:type settingsId:settingsId finished:^(BOOL hasTopLine, BOOL hasAd, BOOL hasCommonMenu, NSArray<SEGNeighborRollViewModel *> *neighborTopLineData) {
        if (completion) completion(hasTopLine, hasAd, hasCommonMenu, neighborTopLineData);
    }];
}

/// 请求网络菜单页面数据
/// @param menuSid 页面Id
/// @param action 页面编码
/// @param settingsId  导航菜单id
/// @param hotNewsParams 侧滑推荐位参数
/// @param targetVC 控制器
/// @param type 广告类型
/// @param completion 回调
- (void)menu_requestNetworkMenuForPageWithMenuSid:(NSString *)menuSid action:(NSString *)action settingsId:(NSString *)settingsId hotNewsParams:(NSDictionary *)hotNewsParams targetVC:(UIViewController *)targetVC positionType:(SEGAdvlistType)type completion:(seg_menu_block)completion {
    [self.menuListManager segReqqustMenuDataAndBusinessDataWithMenuSid:menuSid action:action PositionType:type settingsId:settingsId hotNewsParams:hotNewsParams targetVC:targetVC Finished:^(BOOL hasTopLine, BOOL hasAd, BOOL hasCommonMenu, NSArray<SEGNeighborRollViewModel *> *neighborTopLineData) {
        if (completion) completion(hasTopLine, hasAd, hasCommonMenu, neighborTopLineData);
    }];
}

/// 查询菜单数据中是否存在导航栏，存在返回数据模型，不存在返回nil
/// @param data 菜单数据
+ (SEGMenuListModel *)menu_getNavigationBarMenuWithData:(NSArray<NSArray<SEGMenuListModel *> *> *)data {
    return [SEGMenuListManager segGetNavigationBarData:data];
}

#pragma mark - 老PGC
/// 请求老PGC列表数据
/// @param pageNo 页数
/// @param pageSize 每页总数
/// @param quizTypeId PGC类型
/// @param isRecommend 是否是推荐位
/// @param finished 回调
- (void)menu_requestOldPGCListWithPageNo:(NSInteger)pageNo PageSize:(NSInteger)pageSize quizTypeId:(NSString *)quizTypeId isRecommend:(NSString *)isRecommend finished:(SEGNetworkReponse)finished {
    /// 所以平台可以共用
    __weak typeof(self) weakSelf = self;
    [self.menuListManager requestOldPGCListPageNo:pageNo PageSize:pageSize quizTypeId:quizTypeId isRecommend:isRecommend finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        weakSelf.oldPGCDataSource = weakSelf.menuListManager.oldPGCDataSource;
        weakSelf.oldPGCFreshCount = weakSelf.menuListManager.oldPGCFreshCount;
        if (finished) finished(isSuccessed, result, codeType, errorMessage);
    }];
}

#pragma mark - 查询菜单数据中是否有H5缴费菜单
/// 查询菜单数据中是否有H5缴费菜单
- (id)menu_getWebBillPayURL {
    return [[SEGMenulist2Manager sharedManager] getWebBillPayURL];
}

#pragma mark - Getter
+ (NSArray<SEGMenuListModel *> *)menuListTab {
    return [SEGMenulist2Manager sharedManager].menuListTab;
}
- (NSArray<NSArray<SEGMenuListModel *> *> *)menuListDataArr {
    return self.menuListManager.menuListDataArr;
}
- (SEGPgcManager *)pgcManager {
    return self.menuListManager.pgcManager;
}
- (SEGMenuListManager *)menuListManager {
    if (!_menuListManager) _menuListManager = [SEGMenuListManager new];
    return _menuListManager;
}
- (SEGParkMenuListManager *)parkMenuListManager {
    if (!_parkMenuListManager) _parkMenuListManager = [SEGParkMenuListManager new];
    return _parkMenuListManager;
}
- (NSArray<SEGOldPGCListViewLayout *> *)oldPGCDataSource {
    if (!_oldPGCDataSource) _oldPGCDataSource = [NSArray array];
    return _oldPGCDataSource;
}

@end
